import { validateMobilePipe } from './../pipe/ValidateMobilePipe';
import { Controller, Get, Param, UseFilters, ParseIntPipe, Put, Body, Post } from '@nestjs/common';
import { UsersDto } from 'src/core/dto/users.dto';
import { UsersService } from 'src/core/service/users.service';
import { HttpExceptionFilter } from '../filter/HttpExceptionFilter';
import { id } from 'date-fns/locale';
import { ValidationPipe } from '../pipe/ValidationPipe';
@Controller('users')
export class UsersController {
  constructor(private readonly userService: UsersService) {}

  @Get()
  @UseFilters(new HttpExceptionFilter())
  async searchUsers(): Promise<UsersDto[]> {
    return this.userService.searchUsers();
  }

  @Get(':id')
  async getUser(@Param('id',ParseIntPipe) id: number): Promise<UsersDto> {
    throw new Error;//添加throw异常
    
    return this.userService.getUser(id);
  }
// 修改手机号
@Put(':id/modifyMobile')
modifyMobile(
  @Param('id', ParseIntPipe) id: number,
  @Body('mobile', validateMobilePipe) mobile: string,
) {
  return {id, mobile};
}
//创建用户
@Post()
createUsers(@Body (ValidationPipe)UsersDto:UsersDto){
  return UsersDto
}
}